package com.hyz.login.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.login.model.Cashier;
import com.hyz.login.service.CashierService;
import com.hyz.login.service.PharmacyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2022-11-22
 */
@Controller

public class CashierController {
    Logger logger = LoggerFactory.getLogger(CashierController.class);


    @Autowired
    private CashierService cashierService;
    @Autowired
    private PharmacyService pharmacyService;

    @RequestMapping("/page/caocc/seljiao")
    @ResponseBody
    public Integer seljiao(Integer reid){
        return cashierService.findCountCashierFei(reid);
    }

    @RequestMapping("/page/caocc/selwei")
    @ResponseBody
    public Integer selwei(Integer reid){
        return cashierService.findCountCashierProject(reid);
    }

    @RequestMapping("/page/caoout/selch")
    @ResponseBody
    public Integer selch(Integer reportId){
        return cashierService.findById(reportId);
    }

    @RequestMapping("/page/caoout/shoufei")
    @ResponseBody
    public Integer shoufei(Integer reportId,Double price){
        return cashierService.modifyFeiById(reportId);
    }


    @RequestMapping("/page/caocc/selximu")
    @ResponseBody
    public String selximu(Integer perid,
                          @RequestParam(required = false,defaultValue = "1")Integer page,
                          @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Cashier> iPage = cashierService.findProjectList(perid,page,limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @RequestMapping("/page/caocc/addchuo")
    @ResponseBody
    public Integer addchu(Cashier cashier,Integer drugstorenum){
        pharmacyService.modifyDrugstorenum(cashier.getDurgname(),drugstorenum);
        cashier.setState(1);
        return cashierService.addCashier(cashier);
    }

    @RequestMapping("/page/rep/delo")
    @ResponseBody
    public String delo(Integer cashier){
        if (cashierService.delById(cashier)>0){
            return "删除成功";
        }
        return "删除失败";
    }

    @RequestMapping("/page/caocc/selall")
    @ResponseBody
    public Object selall(Integer perid,
                         @RequestParam(required = false,defaultValue = "1")Integer page,
                         @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Cashier> iPage = cashierService.findProjectList(perid,page,limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }


    @RequestMapping("/page/xpay/selcha")
    @ResponseBody
    public Object selcha(Integer perid,
                         @RequestParam(required = false,defaultValue = "1")Integer page,
                         @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Cashier> iPage = cashierService.findProjectList(perid,page,limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }


    @RequestMapping("/page/xpay/addbing")
    @ResponseBody
    public Object xpayAddbing(Integer reid,String bing,Integer cashier){
        return cashierService.modifyProjectByCashier(reid, bing, cashier);
    }

    @RequestMapping("/page/caocc/selallById")
    @ResponseBody
    public String selallById(Integer perid,
                       @RequestParam(required = false,defaultValue = "1")Integer page,
                       @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Cashier> iPage = cashierService.findCashierByReportId(perid,page,limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @RequestMapping("/page/caotake/zong")
    @ResponseBody
    public Integer zong(Integer reid){
        return cashierService.findSumByReportId(reid);
    }
}

